package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("查询热门讲师、课程等")
@RestController
@CrossOrigin
@RequestMapping("eduservice/courseTeacherfront")
public class EduHotController {
    @Autowired
    EduCourseService eduCourseService;
    @Autowired
    EduTeacherService eduTeacherService;

    @ApiOperation(value = "查询前8条热门课程，查询前4条名师")
    @GetMapping("getFrontInfo")
    public R getFrontInfo() {
        //查询热门课程前8
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last("limit 8");
        List<EduCourse> courses = eduCourseService.list(wrapper);
        //查询资历最高的老师前4做热门排行

        QueryWrapper<EduTeacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("sort");
        wrapper1.last("limit 4");
        List<EduTeacher> teachers = eduTeacherService.list(wrapper1);
        return R.ok().data("eduList", courses).data("teacherList", teachers);
    }

}
